'use strict';

angular.module('com.dcos.app').controller('UserController',function($window,$scope,$uibModalInstance,reload,type,ProjectRightService,UserCenterService) {
  var vm = this;

  vm.curProjectId=$window.sessionStorage.getItem("curProjectId");

  vm.dept_id=$window.sessionStorage.getItem("curDept_Id");

  vm.usertype=$window.sessionStorage.getItem("curUserType");

  vm.userData=[];

  vm.getUserList = function() {
    UserCenterService.getlist(vm.usertype,vm.dept_id).then(function (response) {
      if(response.data.list!=null){
        vm.userData=response.data.list;
        vm.userid=vm.userData[0].userid;
      }
    });
  }
  vm.getUserList();

  vm.ok = function () {
    if(type=="create"){
      ProjectRightService.add(vm.curProjectId,vm.userid).then(function (response) {
          reload();
          $uibModalInstance.dismiss('cancel');
      });
    }else{
      UserCenterService.update(vm.user).then(function (response) {
          reload();
          $uibModalInstance.dismiss('cancel');
      });
    }
  }

  vm.cancel = function () {
    $uibModalInstance.dismiss('cancel');
  };
  
});
